package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.common.contant.ConstantEnum;
import io.renren.entity.FileManagerEntity;
import io.renren.modules.sys.service.FileManagerService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.entity.CompanyProfileEntity;
import io.renren.modules.sys.service.CompanyProfileService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-01-04 13:46:47
 */
@RestController
@RequestMapping("sys/companyprofile")
public class CompanyProfileController {
    @Autowired
    private CompanyProfileService companyProfileService;
    @Autowired
    private FileManagerService fileManagerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("companyprofile:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = companyProfileService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("companyprofile:info")
    public R info(@PathVariable("id") Integer id){
			CompanyProfileEntity companyProfile = companyProfileService.selectById(id);
            Map<String, Object> params = new HashMap<>();
            params.put("recordId",companyProfile.getId());
            params.put("attachType", ConstantEnum.getValueByIndex("COMPANY_PROFILE_001"));//公司详情轮播图
            List<FileManagerEntity> list = fileManagerService.queryList(params);
        return R.ok().put("companyProfile", companyProfile).put("files",list);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("companyprofile:save")
    public R save(@RequestBody CompanyProfileEntity companyProfile){
			companyProfileService.insert(companyProfile);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("companyprofile:update")
    public R update(@RequestBody CompanyProfileEntity companyProfile){
			companyProfileService.updateById(companyProfile);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("companyprofile:delete")
    public R delete(@RequestBody String[] primaryResourcess){
			companyProfileService.deleteBatchIds(Arrays.asList(primaryResourcess));

        return R.ok();
    }

}
